package ca.tatham.scheduler.simulate;

import ca.tatham.scheduler.Task;

public class ResourcesSimulation extends AbstractSchedulerSimulation {
	public static void main(String[] args) throws Exception {
		ResourcesSimulation simulation = new ResourcesSimulation();
		simulation.simulate();
	}

	private void simulate() throws Exception {
		TaskDiagram d = new TaskDiagram(4);

		Object r0 = createResource(0);
		Object r1 = createResource(1);
		Object r2 = createResource(2);

		// Task0 requires resource0 from time 1-3 and resource1 from 4-6 after
		// it starts
		ResourceRequirement[] req0 = new ResourceRequirement[] {
				new ResourceRequirement(r0, 1, 3),
				new ResourceRequirement(r1, 4, 6) };
		Task task0 = new SimulatedTask("Task0", 0, d.addTask('0'), 10, req0);

		// Task1 requires resource2 from time 1-3 after it starts
		ResourceRequirement[] req1 = new ResourceRequirement[] { new ResourceRequirement(
				r2, 1, 3) };
		Task task1 = new SimulatedTask("Task1", 1, d.addTask('1'), 10, req1);

		// Task2 requires resource2 from time 1-8 and resource1 from 3-6
		ResourceRequirement[] req2 = new ResourceRequirement[] {
				new ResourceRequirement(r2, 1, 8),
				new ResourceRequirement(r1, 3, 6) };
		Task task2 = new SimulatedTask("Task2", 2, d.addTask('2'), 10, req2);

		// Start task2 at absolute 0, task1 at 2 and task0 at 5.
		Task[] tasks = new Task[] { task2, task1, task0 };
		int[] delays = new int[] { 0, 2, 5 };
		execute(d, tasks, delays);
	}

}
